﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.IO;

namespace SHA_1
{
    class SHA1Calc
    {
        static void Main(string[] args)
        {
            MemoryStream memstr = new MemoryStream();
            using (FileStream inFile = new FileStream("input.bin", FileMode.Open, FileAccess.Read),
                outFile = new FileStream("output.bin", FileMode.Create, FileAccess.Write))
            {
                byte[] buffer = new byte[1024];
                while (true)
                {
                    int bytesRead = inFile.Read(buffer, 0, buffer.Length);
                    if (bytesRead == 0)
                    {
                        break;
                    }
                    memstr.Write(buffer, 0, bytesRead);
                }
                byte[] data = memstr.ToArray();
                SHA1 sha = new SHA1CryptoServiceProvider();
                byte[] sha1Hash = sha.ComputeHash(data);
                outFile.Write(sha1Hash, 0, sha1Hash.Length);
            }
        }
    }
}
